package com.ssh.tts.dao;

import java.util.List;

import com.ssh.tts.model.Iou;
import com.ssh.utils.DBConnection;

public class IouDao {
	/**
	 * 购票
	 * @param iou
	 * @return
	 */
	public int addIou(Iou iou) {
		String sql = "insert into iou values (iou_id.nextval, ?, ?, ?, ?, ?)";
		return DBConnection.update(sql, new Object[] {iou.getIOU_USER_ID(), iou.getIOU_TRAIN_TRAINID(), iou.getIOU_BUYDATE(), iou.getIOU_TICKETNUMBER(), iou.getIOU_TOTALFARES()});
	}
	
	/**
	 * 退票是根据user_id查询
	 * @param user_id
	 * @return
	 */
	public List<Iou> queryByUser_id(Integer user_id) {
		String sql = "select * from iou where iou_user_id = ?";
		return DBConnection.query(sql, Iou.class, user_id);
	}
	
	/**
	 * 退票
	 * @param iou
	 * @return
	 */
	public int deleteIou(Iou iou) {
		String sql = "delete from iou where iou_user_id = ? and iou_train_trainId = ?";
		return DBConnection.update(sql, new Object[] {iou.getIOU_USER_ID(), iou.getIOU_TRAIN_TRAINID()});
	}
}
